﻿using System;
using UnityEngine;

namespace KuiHuaBaoDian.Services.Guide {

    public abstract class GuideEntity : ScriptableObject {

        [SerializeField, HideInInspector]
        private string m_GUID;
        internal Guid GUID { get => GetGUID(m_GUID); set => m_GUID = value.ToString(); }

        [SerializeField, HideInInspector]
        internal Vector2 m_Position;
        internal Vector2 Position { get => m_Position; set => m_Position = value; }

        [SerializeField, HideInInspector]
        private string m_OutputTo;
        internal Guid OutputTo { get => GetGUID(m_OutputTo); set => m_OutputTo = value.ToString(); }

        [SerializeField, HideInInspector]
        private string m_NextTo;
        internal Guid NextTo { get => GetGUID(m_NextTo); set => m_NextTo = value.ToString(); }

        private Guid GetGUID(string hex) {
            if (Guid.TryParse(hex, out var result)) {
                return result;
            }
            return Guid.Empty;
        }

        protected T GetEnumValue<T>(string name, T defaultValue) where T : Enum {
            var result = defaultValue;
            if (!string.IsNullOrWhiteSpace(name)) {
                if (Enum.TryParse(typeof(T), name, true, out var value)) {
                    result = (T)value;
                }
            }
            return result;
        }
    }

    public interface IGuideEntityHasInput { }

    public interface IGuideEntityHasOutput { }

    public interface IGuideEntityHasPrev { }

    public interface IGuideEntityHasNext { }

    public interface IGuideRequired { }
}
